home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1995 / MacHack 1995.toast / Presentations / Presentations ’92 / Chris Haupt (tcpæ) / tcpæ Ultrix⁄RISC Client (done) / sample_aeclient.c < prev    next >
Text File  |  1992-06-15  |  2KB  |  92 lines

  1. /*
  2. ** Program: aeclient
  3. **    - an apple event generator program for a TCP host
  4. ** Author: cf haupt
  5. ** Created: 09-apr-1992
  6. **
  7. */
  8.  
  9. #include    <stdio.h>
  10. #include    "tcpae.h"
  11.  
  12. /*
  13. **
  14. */
  15. main (int argc, char *argv[])
  16. {
  17.     int     i,
  18.         simple = 0;
  19.     short   context;
  20.  
  21.     char   *hostname = 0,
  22.        *oapp_sig = 0, *quit_sig = 0, *script_sig = 0;
  23.  
  24.     if (argc < 2) {
  25.         fprintf (stderr, "syntax: %s [-host name] [-quit signature] ", argv[0]);
  26.     fprintf (stderr, "[-oapp signature] [-stat] \n");
  27.     fprintf (stderr, "[-dosc signature < script]\n");
  28.         fprintf (stderr,
  29.         "The default host is given by the TCPAEGATEHOST enviroment variable.\n");
  30.         exit (1);
  31.     }
  32.  
  33.     for (i = 1; i < argc; i++) {
  34.     if (argv[i][0] == '-') {
  35.         if (strncmp (argv[i], "-host", 5) == 0) {
  36.         hostname = argv[++i];
  37.         }
  38.         else if (strncmp(argv[i],"-stat",5) == 0)
  39.         simple |= 0x01;
  40.         else if (strncmp(argv[i],"-oapp",5) == 0){
  41.         oapp_sig = argv[++i];
  42.         simple |= 0x02;
  43.        } 
  44.         else if (strncmp(argv[i],"-quit",5) == 0){
  45.         quit_sig = argv[++i];
  46.         simple |= 0x04;
  47.        }
  48.         else if (strncmp(argv[i],"-do",3) == 0){
  49.         script_sig = argv[++i];
  50.         simple |= 0x08;
  51.        }
  52.     }
  53.     }
  54.  
  55. /* decide if we should open link*/
  56.     if (simple) 
  57.     {
  58.     TCPAEInit();
  59.     fprintf(stderr, "Opening gate %d\n", TCPAEOpenGate(&context, hostname));
  60.  
  61.     if (context != kNoContext)
  62.     {
  63.     StatusRec    statRec;
  64. /* do commands found on command line */
  65.         if (simple & 0x01)
  66.     {
  67.         TCPAEGateStatus (context,&statRec);
  68.         fprintf(stderr,
  69.         "Returned Status:\nversion: %d\nfilter:%d\npackets:%d\n",
  70.         statRec.version, statRec.filterFlags, statRec.packetsServed);
  71.     }
  72.         if (simple & 0x02) TCPAESendOAPP(context, oapp_sig);
  73.         if (simple & 0x04) TCPAESendQUIT(context, quit_sig);
  74.         if (simple & 0x08) 
  75.     {
  76.         char c; int i; char *script;
  77.         script = (char *) calloc(1,sizeof(char));
  78.         while ((c = getchar()) != EOF) 
  79.         {
  80.         script[i++] = c;
  81.         realloc(script, strlen(script) + 1);
  82.         }
  83.         TCPAESendDOSC(context, script_sig, script);
  84.         free(script);
  85.     }
  86.  
  87. /* close the connection is it was open */
  88.     TCPAECloseGate(context);
  89.     }
  90.     }
  91. }
  92.